<template>
  <div class="details-container">
    <h3 class="title">{{ photo.title }}</h3>
    <p class="subtitle">
      <span>发表时间：{{ photo.add_time | dateFormat }}</span>
      <span>点击{{ photo.hits }}次</span>
    </p>
    <hr>
    <!-- 缩略图区域 -->
    <vue-preview :slides="thumbnails" @close="handleClose"></vue-preview>
    <div class="content" v-html="photo.description">
    </div>
    <!-- 评论 -->
    <comments></comments>
  </div>
</template>

<script>
import comments from "../common/Comments.vue";
import { Toast } from "mint-ui";
export default {
  data() {
    return {
      id: this.$route.params.id,
      photo: {},
      thumbnails: []
    };
  },
  created() {
    this.getPhotoDetails();
    this.getThumbnails();
  },
  methods: {
    getPhotoDetails() {
      this.$http.get("getphoto?id=" + this.id).then(result => {
        if (result.status === 200 && result.body.length === 1)
          this.photo = result.body[0];
        else Toast("获取图片信息失败");
      });
    },
    getThumbnails() {
      this.$http.get("getthumbnails").then(result => {
        if (result.status === 200) {
          result.body.forEach(item => {
            item.w = 600;
            item.h = 400;
          });
          this.thumbnails = result.body;
        } else Toast("获取缩略图信息失败");
      });
    },
    handleClose() {}
  },
  components: {
    comments
  }
};
</script>

<style lang="scss" scoped>
.details-container {
  padding: 3px;
  .title {
    font-size: 15px;
    text-align: center;
    margin: 15px 0;
    color: #26a2ff;
  }
  .subtitle {
    font-size: 13px;
    display: flex;
    justify-content: space-between;
  }
  .content {
    font-size: 13px;
    line-height: 30px;
  }
}
</style>

